<?php

namespace Common\Model;
use Think\Model;
use Common\Model\UserHospitalModel;

class HospitalLoginLogic extends Model {

	protected $tableName = 'user_hospital';

  private $hospitalModel;

  /**
   * 120端用户登陆
   */
 	public function login($account,$password){
    $this->hospitalModel = new UserHospitalModel;
    if($this->hospitalModel->isPhoneExist($account)){
      $this->hospitalModel->where(['phone'=>$account])->find();
      return $this->checkPasswordAndRecordToken($password);
    }

    return '用户不存在';
  }

  /**
   * 检查密码，处理token
   */
  public function checkPasswordAndRecordToken($password){
    if($this->hospitalModel->password != $this->hospitalModel->getPassword($password)){
      return '密码不正确，请重试';
    }

    return true;
  }

  /**
   * 获取用户登陆token
   */
  public function getLoginToken(){
    return $this->hospitalModel->getToken();
  }

  /**
   * 获取用户登录id
   * @return int
   */
  public function getUserId(){
    return $this->hospitalModel->id;
  }

}